#pragma once
#include<iostream>
#include<string>
#include<functional>
#include<pthread.h>
#include<unistd.h>
#include"logMessage.hpp"
using std::string;
class Task{
    public:
        using callback_t=std::function<void(int,string,uint16_t)>;
        Task()
            :_sock(-1)
            ,_port(-1){}
        Task(int sock,string ip,uint16_t port,callback_t func)
            :_sock(sock)
            ,_ip(ip)
            ,_port(port)
            ,_func(func){}
        void operator()(){
            logMessage(DEBUG,"Thread[%p] has done %s:%d request ---start",pthread_self(),_ip.c_str(),_port);
            _func(_sock,_ip,_port);
            logMessage(DEBUG,"Thread[%p] has done %s:%d request ---end",pthread_self(),_ip.c_str(),_port);
        }
        void run(){
            (*this)();
        }
    private:
        int _sock;
        string _ip;
        uint16_t _port;
        callback_t _func;
};
